package com.ruoyi.activiti.controller;

import com.github.pagehelper.Page;
import com.ruoyi.activiti.domain.ActTaskDTO;
import com.ruoyi.activiti.service.ApprovalService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.api.dto.ActApprovalDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangenhao
 * @className ApprovalController
 * @description 审核controller
 * @date 2024-10-30 下午9:15
 **/
@RestController
@RequestMapping("/approval")
@Slf4j
public class ApprovalController extends BaseController {

    @Autowired
    private ApprovalService approvalService;


    /**
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @description 添加审核
     * @date 2024/10/30 下午10:21
     **/
    @PostMapping("/add")
    public AjaxResult addApproval(@RequestBody ActApprovalDTO actApprovalDTO) {
        log.info("ApprovalController addApproval actApprovalDTO: {}", actApprovalDTO);
        AjaxResult ajaxResult = approvalService.addApproval(actApprovalDTO);
        log.info("ApprovalController addApproval ajaxResult: {}", ajaxResult);
        return ajaxResult;
    }

    /**
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @description 获取审核列表
     * @date 2024/10/30 下午10:21
     **/
    @GetMapping("/list")
    public TableDataInfo getTaskList(String processDefinitionKey) {
        log.info("ApprovalController getTaskList processDefinitionKey:{}", processDefinitionKey);
        Page<ActTaskDTO> actTaskDTOPage = approvalService.getTaskList(processDefinitionKey);
        TableDataInfo tableDataInfo = getDataTable(actTaskDTOPage);
        log.info("ApprovalController getTaskList tableDataInfo:{}", tableDataInfo);
        return tableDataInfo;
    }

    //渲染表单
    @GetMapping(value = "/formDataShow/{taskID}")
    public AjaxResult formDataShow(@PathVariable("taskID") String taskID) {
        log.info("ApprovalController formDataShow taskID:{}", taskID);
        return approvalService.formDataShow(taskID);
    }


    /**
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @description 展示采购退货审核详情
     * @date 2024/11/7 下午2:32
     **/
    @GetMapping(value = "/buyBackOrderShow/{taskId}")
    public AjaxResult buyBackOrderShow(@PathVariable("taskId") String taskId) {
        log.info("ApprovalController buyBackOrderShow taskID:{}", taskId);
        return approvalService.buyBackOrderShow(taskId);
    }

    /**
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @description 展示财务应收单审核详情
     * @date 2024/11/10 下午11:05
     * @Param taskId:
     **/
    @GetMapping(value = "/reciveReqShow/{taskId}")
    public AjaxResult reciveReqShow(@PathVariable("taskId") String taskId) {
        log.info("ApprovalController reciveReqShow taskID:{}", taskId);
        return approvalService.reciveReqShow(taskId);
    }

    @GetMapping("/reciveOrderShow/{taskId}")
    public AjaxResult reciveOrderShow(@PathVariable("taskId") String taskId) {
        log.info("ApprovalController reciveOrderShow taskID:{}", taskId);
        return approvalService.reciveOrderShow(taskId);
    }

    @GetMapping("/saleBackReqShow/{taskId}")
    public AjaxResult saleBackReqShow(@PathVariable("taskId") String taskId) {
        log.info("ApprovalController saleBackReqShow taskID:{}", taskId);
        return approvalService.saleBackReqShow(taskId);
    }

    /**
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @description 处理审核
     * @date 2024/10/30 下午10:21
     **/
    @PostMapping("/handel")
    public AjaxResult handelApproval(@RequestBody ActApprovalDTO actApprovalDTO) {
        log.info("ApprovalController handelApproval start ...");
        AjaxResult ajaxResult = approvalService.handelApproval(actApprovalDTO);
        log.info("ApprovalController handelApproval ajaxResult: {}", ajaxResult);
        return ajaxResult;
    }

    @PostMapping("/saleHandelApproval")
    public AjaxResult saleHandelApproval(@RequestBody String processInstanceId) {
        log.info("ApprovalController saleHandelApproval start ...");
        AjaxResult ajaxResult = approvalService.saleHandelApproval(processInstanceId);
        return ajaxResult;
    }

}
